import getopt
import json, jsonpath
import os
import sys
import time

import pytest
import csv

import requests


def get_env():
    env = getopt.getopt(sys.argv, '-h')
    print('本次执行环境为：' + env[1][1])
    return env[1][1]
    # return "SIT"    # 调试用


def get_test_case():
    case = getopt.getopt(sys.argv, '-h')
    return case[1][2]
    # return "Gitee_UI-新建仓库"


# 本地生成allure报告
def run():
    if get_env() == 'UAT':
        pytest.main(
            ['-s', '-v', '-m', 'full', os.path.dirname(__file__) + rf'/test_case_Gongsi/Gitee_{get_test_case()}.py',
             '--alluredir',
             os.path.dirname(__file__) + './report/allure_temp/', '--clean-alluredir'])
        os.system("allure generate " + os.path.dirname(__file__) + "./report/allure_temp/ -o " + os.path.dirname(
            __file__) + "./report/allure_report_%s --clean" % get_env())
        # outputExc(get_env()) # 输出测试通过率
    elif 'SIT' in get_env():
        allure_dir = f'/root/.jenkins/workspace/giteeUi/allure-results'
        pytest.main(
            ['-vs', '-m full', f'/root/.jenkins/workspace/giteeUi/test_case_Gongsi/{get_test_case()}.py', '--alluredir', allure_dir, '--clean-alluredir']
        )
    elif 'DEV' in get_env():
        pytest.main(['-s', '-v', '-m', 'full', os.path.dirname(__file__) + r'/test_case_Gongsi', '--alluredir',
                     os.path.dirname(__file__) + './report/allure_temp/',
                     '--clean-alluredir'])  # ,'-k login or agencyContract'
        os.system("allure generate " + os.path.dirname(__file__) + "./report/allure_temp/ -o " + os.path.dirname(
            __file__) + "./report/allure_report_%s --clean" % get_env())
    else:
        print('！！！！！！！！！！！！！！！！！！！！环境输入错误！！！！！！！！！！！！！！！！！！！！')


if __name__ == '__main__':
    run()
    # a = os.path.dirname(__file__) + r'\data\通用pdf.pdf'
    # print(a)
    # get_env()
